import logging
import random

from aiogram import Dispatcher, types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters import Text
from aiogram.dispatcher.filters.state import State, StatesGroup

import client_kb
import handlers.users.generate.it_country.country_menu
import sqlite_db
from aiocryptopay import AioCryptoPay
from pyqiwip2p import QiwiP2P
from handlers.users.generate import br_country, mx_country
from handlers.users.generate.ar_country import (
    ar_country_menu,
    ar_id_generate,
    ar_pass_generate,
)
from config import Settings, load_config
from handlers.users.generate.br_country_dir.br_dl import dl_last_name_input
from handlers.users.generate.br_country_dir.br_pass import pass_last_name_input
from handlers.users.generate.de_country import de_country_menu
from handlers.users.generate.es_country import es_country_menu
from handlers.users.generate.est_country import est_country_menu
from handlers.users.generate.kz_country import (
    kz_country_menu,
    kz_id_new_generate,
    kz_id_old_generate,
    kz_pass_generate,
)
from handlers.users.generate.mx_country import (
    mx_bill,
    mx_country_menu,
    mx_pass_generate,
)
from main import bot

logger = logging.getLogger(__name__)

from handlers.users.generate import br_country, mx_country, uk_country


async def check_go(message: types.Message):
    await sqlite_db.sql_command_check(message)
    return


class FSM(StatesGroup):
    create_menu = State()
    promo_quest = State()
    promo_check = State()

    ####
    choise_pay = State()


async def command_promo_quest(callback: types.CallbackQuery, state: FSMContext):
    user_id = callback.from_user.id
    async with state.proxy() as data:
        country = data["pay_country"]
    logger.info(
        f"Пользователем {callback.from_user.username} вызвана функция оплаты. Страна: {country}"
    )
    if await sqlite_db.sql_check_sub(user_id):
        await sqlite_db.sql_give_pasp_sub(user_id, country)
        await state.finish()
    else:
        await bot.send_message(
            callback.from_user.id,
            f"У вас есть промокод?",
            reply_markup=client_kb.kb_inline_promo,
        )
        await FSM.promo_quest.set()


async def command_give_promo(callback: types.CallbackQuery):
    try:
        await bot.delete_message(callback.from_user.id, callback.message.message_id)
    except:
        pass
    await bot.send_message(
        callback.from_user.id,
        "Введите и отправьте промокод",
        reply_markup=client_kb.kb_cancel,
    )
    await FSM.promo_check.set()


async def command_give_promo_insert(message: types.Message, state: FSMContext):
    promo = message.text
    await sqlite_db.sql_command_check_promo(message, state, promo)


async def command_pass_promo(callback: types.CallbackQuery, state: FSMContext):
    user_id = callback.from_user.id
    try:
        await bot.delete_message(callback.from_user.id, callback.message.message_id)
    except:
        pass
    async with state.proxy() as data:
        print(data)
        country = data["pay_country"]
    await state.finish()
    promo_discount = 0
    promo_name = "отсутствует"
    await choise_pay(user_id, country, promo_discount, state, promo_name)
    # await top_up_inline(callback, country, promo_discount, state, promo_name)


async def choise_pay(
    user_id: int, country, promo_discount: int, state: FSMContext, promo_name: str
):
    balance_user = await sqlite_db.get_user_balance(user_id)
    config = load_config()  # TODO Убрать позже
    if "bill" in country:
        price = float(config.payment.price_bill)
    else:
        price = float(config.payment.price_pasp)
    if promo_discount != 0:
        price = price - ((float(price) * float(promo_discount)) / 100)
    if float(balance_user) <= float(price):
        choise_pay = await bot.send_message(
            user_id,
            f"Выберите способ оплаты по кнопке ниже",
            reply_markup=client_kb.kb_choise_pay,
        )
        async with state.proxy() as data:
            data["choise_pay"] = choise_pay["message_id"]
            data["country_pay"] = country
            data["promo_discount_pay"] = promo_discount
            data["promo_name_pay"] = promo_name
    else:
        choise_pay = await bot.send_message(
            user_id,
            f"Ваш баланс позволяет приобрести созданный документ\n"
            f"Цена: {price} руб.\n\n",
            reply_markup=client_kb.kb_go_pay_with_balance,
        )
        async with state.proxy() as data:
            data["choise_pay"] = choise_pay["message_id"]
            data["price_doc"] = float(price)
            data["country_pay"] = country
            data["promo_name_pay"] = promo_name
    await FSM.choise_pay.set()


async def pay_with_balance(callback: types.CallbackQuery, state: FSMContext):
    user_id = callback.from_user.id
    async with state.proxy() as data:
        try:
            await bot.delete_message(
                chat_id=callback.from_user.id, message_id=data["choise_pay"]
            )
        except:
            pass
        country = data["country_pay"]
        promo_name = data["promo_name_pay"]
        price_doc = float(data["price_doc"])
        await sqlite_db.sql_give_doc_from_balance(
            user_id, country, promo_name, price_doc
        )
    await state.finish()


async def top_up_qiwi(
    callback: types.CallbackQuery, state: FSMContext, p2p: QiwiP2P, config: Settings
):
    user_id = callback.from_user.id
    async with state.proxy() as data:
        try:
            await bot.delete_message(
                chat_id=callback.from_user.id, message_id=data["check_pay1"]
            )
        except:
            pass
        country = data["country_pay"]
        promo_discount = int(data["promo_discount_pay"])
        promo_name = data["promo_name_pay"]
    await state.finish()
    if "bill" in country:
        print("bill")
        price = int(config.payment.price_bill)
    else:
        price = int(config.payment.price_pasp)
    if promo_discount != 0:
        price = price - ((int(price) * int(promo_discount)) / 100)
    comment = str(callback.from_user.id) + "_" + str(random.randint(1000, 9999))
    bill = p2p.bill(amount=price, lifetime=180, comment=comment)
    await sqlite_db.add_check_qiwi(user_id, bill.bill_id, country, promo_name)
    check_pay1 = await bot.send_message(
        user_id,
        f'<b>Чтобы произвести оплату нажмите на кнопку "Оплатить"\n\n'
        f"Сумма: {price} ₽\n</b>",
        parse_mode="HTML",
        reply_markup=client_kb.buy_menu_week(url=bill.pay_url, bill=bill.bill_id),
    )
    async with state.proxy() as data:
        data["check_pay1"] = check_pay1["message_id"]


async def check_week(callback: types.CallbackQuery, state: FSMContext, p2p: QiwiP2P):
    user_id = callback.from_user.id
    bill = str(callback.data[8:])
    info = await sqlite_db.get_check(bill)
    if info != False:
        if str(p2p.check(bill_id=bill).status) == "PAID":
            async with state.proxy() as data:
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay1"]
                    )
                except:
                    pass
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay2"]
                    )
                except:
                    pass
            pay = "qiwi"
            await sqlite_db.sql_give_pasp(user_id, bill, pay)
        else:
            async with state.proxy() as data:
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay2"]
                    )
                except:
                    pass
            check_pay2 = await bot.send_message(
                callback.from_user.id,
                f"<b>Вы пока не оплатили счет</b>",
                parse_mode="HTML",
                reply_markup=client_kb.buy_menu_week(False, bill=bill),
            )
            async with state.proxy() as data:
                data["check_pay2"] = check_pay2["message_id"]
    else:
        await bot.send_message(callback.from_user.id, "Счет не найден")


async def top_up_crypto(
    callback: types.CallbackQuery,
    state: FSMContext,
    crypto: AioCryptoPay,
    config: Settings,
):
    user_id = callback.from_user.id
    async with state.proxy() as data:
        try:
            await bot.delete_message(
                chat_id=callback.from_user.id, message_id=data["check_pay1"]
            )
        except:
            pass
        country = data["country_pay"]
        promo_discount = int(data["promo_discount_pay"])
        promo_name = data["promo_name_pay"]
    await state.finish()
    if "bill" in country:
        print("bill")
        price = config.payment.price_bill_crypto
    else:
        price = config.payment.price_pasp_crypto
    if promo_discount != 0:
        price = float(price) - ((float(price) * promo_discount) / 100)
    print(price, "price")
    print(type(price))
    # price = round(float(price), 2)
    # print(price, 'price')
    bill = await crypto.create_invoice(asset="USDT", amount=float(price))
    bill_id = bill.invoice_id
    await sqlite_db.add_check_crypto(user_id, bill_id, country, promo_name)
    check_pay1 = await bot.send_message(
        user_id,
        f'<b>Чтобы произвести оплату нажмите на кнопку "Оплатить"\n\n'
        f"Сумма: {price} USDT\n</b>\n\n"
        f"После оплаты вернитесь в этот бот и завершите покупку",
        parse_mode="HTML",
        reply_markup=client_kb.buy_menu_crypto(url=bill.pay_url, bill=bill_id),
    )
    async with state.proxy() as data:
        data["check_pay1"] = check_pay1["message_id"]


async def check_crypto(
    callback: types.CallbackQuery, state: FSMContext, crypto: AioCryptoPay
):
    user_id = callback.from_user.id
    bill_id = str(callback.data[8:])
    info = await sqlite_db.get_check_crypto(bill_id)
    if info != False:
        invoices = await crypto.get_invoices(invoice_ids=int(bill_id))
        print(invoices)
        print(invoices.status)
        print(str(invoices.status))
        if str(invoices.status) == "paid":
            async with state.proxy() as data:
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay1"]
                    )
                except:
                    pass
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay2"]
                    )
                except:
                    pass
            pay = "crypto"
            await sqlite_db.sql_give_pasp(user_id, bill_id, pay)
        else:
            async with state.proxy() as data:
                try:
                    await bot.delete_message(
                        chat_id=callback.from_user.id, message_id=data["check_pay2"]
                    )
                except:
                    pass
            check_pay2 = await bot.send_message(
                callback.from_user.id,
                f"<b>Вы пока не оплатили счет</b>",
                parse_mode="HTML",
                reply_markup=client_kb.buy_menu_crypto(False, bill=bill_id),
            )
            async with state.proxy() as data:
                data["check_pay2"] = check_pay2["message_id"]
    else:
        await bot.send_message(callback.from_user.id, "Счет не найден")


async def checksss(message: types.Message, crypto: AioCryptoPay):
    check = await crypto.get_exchange_rates()
    print(check)
    usdt_rub_rate = ""
    for rate in check:
        if rate.source == "USDT" and rate.target == "RUB":
            usdt_rub_rate = rate.rate
            break

    print(usdt_rub_rate)


def register_handlers_client(dp: Dispatcher):
    dp.register_message_handler(checksss, Text(equals="go"))

    dp.register_callback_query_handler(
        command_give_promo, Text(equals="give_promo"), state=FSM.promo_quest
    )
    dp.register_message_handler(command_give_promo_insert, state=FSM.promo_check)
    dp.register_callback_query_handler(
        command_pass_promo, Text(equals="pass_promo"), state=FSM.promo_quest
    )
    dp.register_callback_query_handler(
        top_up_qiwi, Text(equals="choice_qiwi"), state=FSM.choise_pay
    )
    dp.register_callback_query_handler(check_week, text_contains="wkcheck_")
    dp.register_callback_query_handler(
        top_up_crypto, Text(equals="choice_crypto"), state=FSM.choise_pay
    )
    dp.register_callback_query_handler(check_crypto, text_contains="crcheck_")
    dp.register_callback_query_handler(
        pay_with_balance, Text(equals="pay_with_balance"), state=FSM.choise_pay
    )

    dp.register_message_handler(
        uk_country.command_create_uk, Text(equals="UK 🇬🇧"), state=FSM.create_menu
    )
    # ukpass
    dp.register_message_handler(
        uk_country.command_create_uk_pass,
        Text(equals="PASS NEW 🇬🇧"),
        state=uk_country.FSM.create_uk_pass,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_name, state=uk_country.FSM.create_uk_pass_name
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_family,
        state=uk_country.FSM.create_uk_pass_family,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_date_birth,
        state=uk_country.FSM.create_uk_pass_date_birth,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_number_generate,
        Text(equals="Сгенерировать"),
        state=uk_country.FSM.create_uk_pass_number,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_number,
        state=uk_country.FSM.create_uk_pass_number,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_natcion,
        state=uk_country.FSM.create_uk_pass_natcion,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_place_birth,
        state=uk_country.FSM.create_uk_pass_place_birth,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_gender,
        state=uk_country.FSM.create_uk_pass_gender,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_date_doc,
        state=uk_country.FSM.create_uk_pass_date_doc,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_photo,
        content_types=types.ContentTypes.ANY,
        state=uk_country.FSM.create_uk_pass_photo,
    )
    dp.register_callback_query_handler(
        uk_country.command_create_uk_pass_signature,
        state=uk_country.FSM.create_uk_pass_signature,
    )
    dp.register_callback_query_handler(
        uk_country.command_create_uk_pass_holo, state=uk_country.FSM.create_uk_pass_holo
    )
    dp.register_message_handler(
        uk_country.command_create_uk_pass_size, state=uk_country.FSM.create_uk_pass_size
    )

    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass,
        Text(equals="uk_change"),
        state=uk_country.FSM.change_uk_pass,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_family,
        Text(equals="uk_change_fam"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_name,
        Text(equals="uk_change_name"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_date_birth,
        Text(equals="uk_change_date_birth"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_number,
        Text(equals="uk_change_pass_number"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_natcion,
        Text(equals="uk_change_natcion"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_place_birth,
        Text(equals="uk_change_place_birth"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_gender,
        Text(equals="uk_change_gender"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_date_doc,
        Text(equals="uk_change_date_doc"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_photo,
        Text(equals="uk_change_photo"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_signature,
        Text(equals="uk_change_signature"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_holo,
        Text(equals="uk_change_holo"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_size,
        Text(equals="uk_change_size_doc"),
        state=uk_country.FSM.change_uk_pass_what,
    )
    dp.register_message_handler(
        uk_country.command_change_uk_pass_go,
        content_types=types.ContentTypes.ANY,
        state=uk_country.FSM.change_uk_pass_go,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_pass_go_inline,
        state=uk_country.FSM.change_uk_pass_go,
    )
    dp.register_callback_query_handler(
        uk_country.command_pay_uk_pass,
        Text(equals="uk_pay"),
        state=uk_country.FSM.change_uk_pass,
    )

    # ukbill
    dp.register_message_handler(
        uk_country.command_create_uk_bill,
        Text(equals="BILL 🇬🇧"),
        state=uk_country.FSM.create_uk_pass,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_family,
        state=uk_country.FSM.create_uk_bill_family,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_name, state=uk_country.FSM.create_uk_bill_name
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_flate_number,
        state=uk_country.FSM.create_uk_bill_flate_number,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_street,
        state=uk_country.FSM.create_uk_bill_street,
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_city, state=uk_country.FSM.create_uk_bill_city
    )
    dp.register_message_handler(
        uk_country.command_create_uk_bill_postcode,
        state=uk_country.FSM.create_uk_bill_postcode,
    )

    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill,
        Text(equals="uk_change_bill"),
        state=uk_country.FSM.change_uk_bill,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_family,
        Text(equals="uk_change_bill_family"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_name,
        Text(equals="uk_change_bill_name"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_flate_number,
        Text(equals="uk_change_bill_flate_number"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_street,
        Text(equals="uk_change_bill_street"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_city,
        Text(equals="uk_change_name_bill_city"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_callback_query_handler(
        uk_country.command_change_uk_bill_postcode,
        Text(equals="uk_change_bill_postcode"),
        state=uk_country.FSM.change_uk_bill_what,
    )
    dp.register_message_handler(
        uk_country.command_change_uk_bill_go,
        content_types=types.ContentTypes.ANY,
        state=uk_country.FSM.change_uk_bill_go,
    )
    dp.register_callback_query_handler(
        uk_country.command_pay_uk_bill,
        Text(equals="uk_pay_bill"),
        state=uk_country.FSM.change_uk_bill,
    )
    # dp.register_message_handler(
    # handlers.users.generate.uk_country.command_create_uk_bill, Text(equals="BILL 🇬🇧")
    # )
    ###############brazilia
    dp.register_message_handler(
        br_country.command_create_br, Text(equals="Brazil 🇧🇷"), state=FSM.create_menu
    )
    # brbill
    dp.register_message_handler(
        br_country.command_create_br_bill,
        Text(equals="BILL 🇧🇷"),
        state=br_country.FSM.create_br_pass,
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_family,
        state=br_country.FSM.create_br_bill_family,
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_name, state=br_country.FSM.create_br_bill_name
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_flate_number,
        state=br_country.FSM.create_br_bill_flate_number,
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_street,
        state=br_country.FSM.create_br_bill_street,
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_city, state=br_country.FSM.create_br_bill_city
    )
    dp.register_message_handler(
        br_country.command_create_br_bill_postcode,
        state=br_country.FSM.create_br_bill_postcode,
    )

    dp.register_callback_query_handler(
        br_country.command_change_br_bill,
        Text(equals="br_change_bill"),
        state=br_country.FSM.change_br_bill,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_family,
        Text(equals="br_change_bill_family"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_name,
        Text(equals="br_change_bill_name"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_flate_number,
        Text(equals="br_change_bill_flate_number"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_street,
        Text(equals="br_change_bill_street"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_city,
        Text(equals="br_change_name_bill_city"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_bill_postcode,
        Text(equals="br_change_bill_postcode"),
        state=br_country.FSM.change_br_bill_what,
    )
    dp.register_message_handler(
        br_country.command_change_br_bill_go,
        content_types=types.ContentTypes.ANY,
        state=br_country.FSM.change_br_bill_go,
    )
    dp.register_callback_query_handler(
        br_country.command_pay_br_bill,
        Text(equals="br_pay_bill"),
        state=br_country.FSM.change_br_bill,
    )
    # brid
    dp.register_message_handler(
        br_country.command_create_br_id,
        Text(equals="ID 🇧🇷"),
        state=br_country.FSM.create_br_pass,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_name, state=br_country.FSM.create_br_id_name
    )
    dp.register_message_handler(
        br_country.command_create_br_id_family, state=br_country.FSM.create_br_id_family
    )
    dp.register_message_handler(
        br_country.command_create_br_id_name_father,
        state=br_country.FSM.create_br_id_name_father,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_name_mother,
        state=br_country.FSM.create_br_id_name_mother,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_date_birth,
        state=br_country.FSM.create_br_id_date_birth,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_place_birth,
        state=br_country.FSM.create_br_id_place_birth,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_pass_number_generate,
        Text(equals="Сгенерировать"),
        state=br_country.FSM.create_br_id_pass_number,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_pass_number,
        state=br_country.FSM.create_br_id_pass_number,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_pass_number_cpf_generate,
        Text(equals="Сгенерировать"),
        state=br_country.FSM.create_br_id_pass_number_cpf,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_pass_number_cpf,
        state=br_country.FSM.create_br_id_pass_number_cpf,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_date_doc,
        state=br_country.FSM.create_br_id_date_doc,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_place_doc,
        state=br_country.FSM.create_br_id_place_doc,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_photo,
        content_types=types.ContentTypes.ANY,
        state=br_country.FSM.create_br_id_photo,
    )
    dp.register_callback_query_handler(
        br_country.command_create_br_id_signature,
        state=br_country.FSM.create_br_id_signature,
    )
    dp.register_message_handler(
        br_country.command_create_br_id_size, state=br_country.FSM.create_br_id_size
    )

    #
    dp.register_callback_query_handler(
        br_country.command_change_br_id,
        Text(equals="br_change_id"),
        state=br_country.FSM.change_br_id,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_name,
        Text(equals="br_change_id_name"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_family,
        Text(equals="br_change_id_family"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_name_father,
        Text(equals="br_change_id_name_father"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_name_mother,
        Text(equals="br_change_id_name_mother"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_date_birth,
        Text(equals="br_change_id_date_birth"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_place_birth,
        Text(equals="br_change_id_place_birth"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_pass_number,
        Text(equals="br_change_id_pass_number"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_pass_number_cpf,
        Text(equals="br_change_id_pass_number_cpf"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_date_doc,
        Text(equals="br_change_id_date_doc"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_place_doc,
        Text(equals="br_change_id_place_doc"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_photo,
        Text(equals="br_change_id_photo"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_signature,
        Text(equals="br_change_id_signature"),
        state=br_country.FSM.change_br_id_what,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_size,
        Text(equals="br_change_id_size"),
        state=br_country.FSM.change_br_id_what,
    )

    dp.register_message_handler(
        br_country.command_change_br_id_go,
        content_types=types.ContentTypes.ANY,
        state=br_country.FSM.change_br_id_go,
    )
    dp.register_callback_query_handler(
        br_country.command_change_br_id_go_inline, state=br_country.FSM.change_br_id_go
    )
    dp.register_callback_query_handler(
        br_country.command_pay_br_id,
        Text(equals="br_pay_id"),
        state=br_country.FSM.change_br_id,
    )

    #################################################################################
    # todo:MAIN
    dp.register_message_handler(
        mx_country_menu.create_mx, Text(equals="Mexico 🇲🇽"), state=FSM.create_menu
    )
    # dp.register_message_handler(
    #     mx_bill.command_create_mx_bill,
    #     Text(equals="BILL 🇲🇽"),
    #     state=mx_bill.FSM.create_mx_bill,
    # )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_family,
        state=mx_bill.FSM.create_mx_bill_family,
    )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_name, state=mx_bill.FSM.create_mx_bill_name
    )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_flate_number,
        state=mx_bill.FSM.create_mx_bill_flate_number,
    )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_street,
        state=mx_bill.FSM.create_mx_bill_street,
    )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_city, state=mx_bill.FSM.create_mx_bill_city
    )
    dp.register_message_handler(
        mx_bill.command_create_mx_bill_postcode,
        state=mx_bill.FSM.create_mx_bill_postcode,
    )

    # todo:CHANGE
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill,
        Text(equals="mx_change_bill"),
        state=mx_bill.FSM.change_mx_bill,
    )

    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_family,
        Text(equals="mx_change_bill_family"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_name,
        Text(equals="mx_change_bill_name"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_flate_number,
        Text(equals="mx_change_bill_flate_number"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_street,
        Text(equals="mx_change_bill_street"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_city,
        Text(equals="mx_change_name_bill_city"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_callback_query_handler(
        mx_bill.command_change_mx_bill_postcode,
        Text(equals="mx_change_bill_postcode"),
        state=mx_bill.FSM.change_mx_bill_what,
    )
    dp.register_message_handler(
        mx_bill.command_change_mx_bill_go,
        content_types=types.ContentTypes.ANY,
        state=mx_bill.FSM.change_mx_bill_go,
    )

    # todo:BUY
    dp.register_callback_query_handler(
        mx_bill.command_pay_mx_bill,
        Text(equals="mx_pay_bill"),
        state=mx_bill.FSM.change_mx_bill,
    )

    # todo:BUY
    dp.register_callback_query_handler(
        mx_bill.command_pay_mx_bill,
        Text(equals="mx_pay_bill"),
        state=mx_bill.FSM.change_mx_bill,
    )

    #################ITALY BILL####################
    dp.register_message_handler(
        handlers.users.generate.it_country.country_menu.create_italy,
        Text(equals="Italy 🇮🇹"),
        state=FSM.create_menu,
    )

    # SPAIN
    dp.register_message_handler(
        es_country_menu.create_spain, Text(equals="Spain 🇪🇸"), state=FSM.create_menu
    )

    # germany
    dp.register_message_handler(
        handlers.users.generate.de_country.de_country_menu.create_germany,
        Text(equals="Germany 🇩🇪"),
        state=FSM.create_menu,
    )

    from handlers.users.generate.kz_country import kz_passport

    dp.register_message_handler(
        kz_country_menu.create_kz, Text(equals="Kazakhstan 🇰🇿"), state=FSM.create_menu
    )

    dp.register_message_handler(
        est_country_menu.create_estonia,
        Text(equals="Estonia 🇪🇪"),
        state=FSM.create_menu,
    )

    dp.register_message_handler(
        ar_country_menu.create_ar, Text(equals="Argentina 🇦🇷"), state=FSM.create_menu
    )
